package com.example.demo.controller;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.example.demo.vo.Hellojson;
import testJdk.anno.older.AuthorAnnotation;
import org.springframework.web.bind.annotation.*;

/**
 * @author keyer
 * @Name : com.example.demo.controller.TestController
 * @Description : 描述
 * Created by cyd on 2021-04-29 15:33:23
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping(value = "/sayHello")
    @AuthorAnnotation(name = "cyd", company = "keyer")
    public String sayHello() {
        System.out.println("method run");
        return "hello world";
    }

    @PostMapping(value = "/sayPostHello")
    @AuthorAnnotation(name = "cyd", company = "keyer")
    public String sayPostHello(@RequestBody Hellojson hellojson) {
        String body = JSONUtil.parse(hellojson).toStringPretty();
        String url = "http://localhost:8081/test/sayPostHello2";
        // 手动发出请求
        HttpResponse response = HttpRequest.post(url).body(body).execute();
        System.out.println("response: "+response.toString());
        System.out.println("Status: "+response.getStatus());
        return response.toString();
    }

    @PostMapping(value = "/sayPostHello2")
    @AuthorAnnotation(name = "cyd", company = "keyer")
    public String sayPostHello2(@RequestBody Hellojson hellojson) {
        hellojson.setContent("sayPostHello2");
        return hellojson.toString();
    }
}



